<?php
class Receipt extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();

		// load helper
		$this->load->helper('url');
		// $this->load->library('session');

		$this->load->model("Product_model", '', TRUE);
		$this->load->model("Stock_receipt_model", '', TRUE);
		$this->load->model("Stock_receipt_product_model", '', TRUE);
	}

	public function index($warehouseId)
	{		
		$data['lstReceipt'] = $this->Stock_receipt_model->All($warehouseId);		

		$data['mainView'] = 'receipt/index';
		$data['warehouseId'] = $warehouseId;
		$this->load->view('shared/layout', $data);
	}

	public function create($warehouseId)
	{
		$data['mainView'] = 'receipt/create';

		// $data['lstProduct'] = $this->Product_model->All($warehouseId);

		$data['warehouseId'] = $warehouseId;
		$this->load->view('shared/layout', $data);
	}	

	public function create_post($warehouseId)
	{
		$employeeId = 1;
		$this->Stock_receipt_model->Add($warehouseId, $employeeId);


		redirect("/product/index/$warehouseId");
	}

	public function list_product($receiptId)
	{		
		$data['lstProduct'] = $this->Stock_receipt_product_model->GetAllProductByReceiptId($receiptId);

		$data['mainView'] = 'receipt/list_product';
		$data['receiptId'] = $receiptId;
		$this->load->view('shared/layout', $data);
	}

	public function check($receiptId)
	{		
		$data['lstProduct'] = $this->Stock_receipt_product_model->GetAllProductByReceiptId($receiptId);

		$data['mainView'] = 'receipt/check';
		$data['receiptId'] = $receiptId;
		$this->load->view('shared/layout', $data);
	}

	public function check_post($id, $mountReal)
	{
		// $id = $_POST['id'];
		// $mountReal = $_POST['mountReal'];//$this->input->post('mountReal');
		$this->Stock_receipt_product_model->UpdateMountReal($id, $mountReal);
		$array = array('result' => 'From controller : ');
		echo json_encode($id);
		// echo $id;
	}

	public function addproduct($receiptId)
	{
		$data['mainView'] = 'receipt/addproduct';

		$warehouseId = $this->Stock_receipt_model->GetWarehouseId($receiptId);

		$data['lstProduct'] = $this->Product_model->All($warehouseId);

		$data['receiptId'] = $receiptId;
		$this->load->view('shared/layout', $data);
	}	

	public function addproduct_post($receiptId)
	{
		$this->Stock_receipt_product_model->Add($receiptId);

		redirect("/receipt/list_product/$receiptId");
	}	
}
?>